﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebSysCore.JSons;

namespace WebSysCore.Helpers
{
    public class AssignHelp
    {
        public static Customer JCustomerToCustomer(JCustomer jc)
        {
            Customer cs = new Customer()
            {
                BankAccount = jc.BankAccount,
                BankName = jc.BankName,
                ContactName = jc.ContactName,
                Email=jc.Email,
                ContactPhone = jc.ContactPhone,
                CustomerAddress = jc.CustomerAddress,
                CustomerDistrictOrCity = jc.CustomerDistrictOrCity,
                CustomerId = jc.CustomerId,
                CustomerName = jc.CustomerName,
                CustomerPhone = jc.CustomerPhone,
                CustomerProvinceId = jc.CustomerProvinceId,
                LoginName = jc.LoginName,
                Password = jc.Password,
                Deleted=jc.Deleted
            };
            return cs;
        }
        public static JCustomer CustomerToJCustomer(Customer cs)
        {
            JCustomer jc = new JCustomer()
            {
                BankAccount = cs.BankAccount,
                Email=cs.Email,
                BankName = cs.BankName,
                ContactName = cs.ContactName,
                ContactPhone = cs.ContactPhone,
                CustomerAddress = cs.CustomerAddress,
                CustomerDistrictOrCity = cs.CustomerDistrictOrCity,
                CustomerId = cs.CustomerId,
                CustomerName = cs.CustomerName,
                CustomerPhone = cs.CustomerPhone,
                CustomerProvinceId = cs.CustomerProvinceId,
                LoginName = cs.LoginName,
                Password = cs.Password,
                Deleted=cs.Deleted

            };
            return jc;
        }

        public static Class JClassToClass(JClass jc)
        {
            Class cl = new Class()
            {
                ClassID = jc.ClassID,
                ClassName = jc.ClassName,
                ClassSize = jc.ClassSize,
                Comment = jc.Comment,
                GroupID = jc.GroupID,
                ScheduleInListId = jc.ScheduleInListId,
                TeacherID = jc.TeacherID

            };
            return cl;
        }
        public static JClass ClassToJClass(Class cl)
        {
            JClass jc = new JClass()
            {
                ClassID = cl.ClassID,
                ClassName = cl.ClassName,
                ClassSize = int.Parse(cl.ClassSize.ToString()),
                Comment = cl.Comment,
                GroupID = cl.GroupID,
                ScheduleInListId = cl.ScheduleInListId,
                TeacherID = cl.TeacherID

            };
            return jc;
        }
        public static Day JDayToDay(JDay jd)
        {
            Day d = new Day()
            {
                Comment = jd.Comment,
                DayID = jd.DayID,
                DayName = jd.DayName,
                Order = jd.Order,
                ScheduleInListId = jd.ScheduleInListId

            };
            return d;
        }
        public static JDay DayToJDay(Day d)
        {
            JDay jd = new JDay()
            {
                Comment = d.Comment,
                DayID = d.DayID,
                DayName = d.DayName,
                Order = d.Order,
                ScheduleInListId = d.ScheduleInListId
            };
            return jd;
        }

        public static FixSubjectSessionLession JFixSSLToFixSSL(JFixSubjectSessionLession js)
        {
            FixSubjectSessionLession fs = new FixSubjectSessionLession()
            {
                Comment = js.Comment,
                DayID = js.DayID,
                FixSubjectSessionLessionID = js.FixSubjectSessionLessionID,
                GroupID = js.GroupID,
                LessionID = js.LessionID,
                ScheduleInListId = js.ScheduleInListId,
                SubjectID = js.SubjectID

            };
            return fs;
        }

        public static JFixSubjectSessionLession FixSSLToJFixSSL(FixSubjectSessionLession fs)
        {
            JFixSubjectSessionLession js = new JFixSubjectSessionLession()
            {
                Comment = fs.Comment,
                DayID = fs.DayID,
                FixSubjectSessionLessionID = fs.FixSubjectSessionLessionID,
                GroupID = fs.GroupID,
                LessionID = fs.LessionID,
                ScheduleInListId = fs.ScheduleInListId,
                SubjectID = fs.SubjectID
            };
            return js;
        }
        public static FixTeacherClassSubject JFixTCSToFixTCS(JFixTeacherClassSubject jt)
        {
            FixTeacherClassSubject ft = new FixTeacherClassSubject()
            {
                ClassID = jt.ClassID,
                Comment = jt.Comment,
                FixTeacherClassSubjectID = jt.FixTeacherClassSubjectID,
                ScheduleInListId = jt.ScheduleInListId,
                SubjectID = jt.SubjectID,
                TeacherID = jt.TeacherID,

            };
            return ft;
        }

        public JFixTeacherClassSubject FixTCSTpJFixTCS(FixTeacherClassSubject ft)
        {
            JFixTeacherClassSubject jt = new JFixTeacherClassSubject()
            {
                ClassID = ft.ClassID,
                Comment = ft.Comment,
                FixTeacherClassSubjectID = ft.FixTeacherClassSubjectID,
                ScheduleInListId = ft.ScheduleInListId,
                SubjectID = ft.SubjectID,
                TeacherID = ft.TeacherID
            };
            return jt;
        }
        public static FixTeacherSession JFixTSToFIxTS(JFixTeacherSession jt)
        {
            FixTeacherSession ft = new FixTeacherSession()
            {
                Comment = jt.Comment,
                DayID = jt.DayID,
                FixTeacherSessionID = jt.FixTeacherSessionID,
                ScheduleInListId = jt.ScheduleInListId,
                SessionID = jt.SessionID,
                TeacherID = jt.TeacherID
            };
            return ft;
        }
        public static JFixTeacherSession FixTSToJFixTS(FixTeacherSession ft)
        {
            JFixTeacherSession jt = new JFixTeacherSession()
            {
                Comment = ft.Comment,
                DayID = ft.DayID,
                FixTeacherSessionID = ft.FixTeacherSessionID,
                ScheduleInListId = ft.ScheduleInListId,
                SessionID = ft.SessionID,
                TeacherID = ft.TeacherID
            };
            return jt;
        }
        public static Group JGroupToGroup(JGroup jg)
        {
            Group g = new Group()
            {
                Comment = jg.Comment,
                GroupID = jg.GroupID,
                GroupName = jg.GroupName,
                ProgramID = jg.ProgramID,
                ScheduleInListId = jg.ScheduleInListId,
                SessionID = jg.SessionID
            };
            return g;
        }
        public static JGroup GroupToJGroup(Group g)
        {
            JGroup jg = new JGroup()
            {
                Comment = g.Comment,
                GroupID = g.GroupID,
                GroupName = g.GroupName,
                ProgramID = g.ProgramID,
                ScheduleInListId = g.ScheduleInListId,
                SessionID = g.SessionID
            };
            return jg;
        }

        public static Lession JLessionToLession(JLession j)
        {
            Lession l = new Lession()
            {
                Comment = j.Comment,
                EndTime = j.EndTime,
                LessionID = j.LessionID,
                Order = j.Order,
                ScheduleInListId = j.ScheduleInListId,
                StartTime = j.StartTime
            };
            return l;
        }
        public static JLession LessionToJLession(Lession l)
        {
            JLession j = new JLession()
            {
                Comment = l.Comment,
                EndTime = l.EndTime,
                LessionID = l.LessionID,
                Order = l.Order,
                ScheduleInListId = l.ScheduleInListId,
                StartTime = l.StartTime
            };
            return j;
        }
        public static ListSchedule JListScheduleToListSchedule(JListSchedule j)
        {
            ListSchedule l = new ListSchedule()
            {
                CreatedDay = DateTime.Parse(j.CreatedDay),
                CustomerId = j.CustomerId,
                InputDay = DateTime.Parse(j.InputDay),
                ScheduleIdInList = j.ScheduleIdInList,
                ScheduleName = j.ScheduleName,
            };
            return l;
        }
        public static JListSchedule ListScheduleToJListSchedule(ListSchedule l)
        {
            JListSchedule j = new JListSchedule()
            {
                CreatedDay = l.CreatedDay.ToString(),
                CustomerId = l.CustomerId,
                InputDay = l.InputDay.ToString(),
                ScheduleIdInList = l.ScheduleIdInList,
                ScheduleName = l.ScheduleName
            };
            return j;
        }

        public static ProgramDetail JProgramDetailToProgramDetail(JProgramDetail j)
        {
            ProgramDetail p = new ProgramDetail()
            {
                Comment = j.Comment,
                NumLession = j.NumLession,
                ProgramID = j.ProgramID,
                SubjectID = j.SubjectID
            };
            return p;
        }
        public static JProgramDetail ProgramDetailToJProgramDetail(ProgramDetail p)
        {
            JProgramDetail j = new JProgramDetail()
            {
                Comment = p.Comment,
                NumLession = p.NumLession,
                ProgramID = p.ProgramID,
                SubjectID = p.SubjectID
            };
            return j;
        }
        public static Program JProgramToProgram(JProgram j)
        {
            Program p = new Program()
            {
                Comment = j.Comment,
                ProgramID = j.ProgramID,
                ProgramName = j.ProgramName,
                ScheduleInListId = j.ScheduleInListId
            };
            return p;
        }
        public static JProgram ProgramToJProgram(Program p)
        {
            JProgram j = new JProgram()
            {
                Comment = p.Comment,
                ProgramID = p.ProgramID,
                ProgramName = p.ProgramName,
                ScheduleInListId = p.ScheduleInListId
            };
            return j;
        }

        public static Province JProvinceToProvince(JProvince j)
        {
            Province p = new Province()
            {
                ProvinceId = j.ProvinceId,
                ProvinceName = j.ProvinceName
            };
            return p;
        }
        public static JProvince ProvinceToJProvince(Province p)
        {
            JProvince j = new JProvince()
            {
                ProvinceId = p.ProvinceId,
                ProvinceName = p.ProvinceName
            };
            return j;
        }
        public static Schedule JScheduleToSchedule(JSchedule j)
        {
            Schedule s = new Schedule()
            {
                ClassID = j.ClassID,
                Comment = j.Comment,
                DayID = j.DayID,
                LessionID = j.LessionID,
                ScheduleID = j.ScheduleID,
                ScheduleIdInList = j.ScheduleIdInList,
                SubjectID = j.SubjectID,
                TeacherID = j.TeacherID
            };
            return s;
        }
        public static JSchedule ScheduleToJSchedule(Schedule s)
        {
            JSchedule j = new JSchedule()
            {
                ClassID = s.ClassID,
                Comment = s.Comment,
                DayID = s.DayID,
                LessionID = s.LessionID,
                ScheduleID = s.ScheduleID,
                ScheduleIdInList = s.ScheduleIdInList,
                SubjectID = s.SubjectID,
                TeacherID = int.Parse(s.TeacherID.ToString())
            };
            return j;
        }
        public static Session JSessionToSession(JSession j)
        {
            Session s = new Session()
            {
                Comment = j.Comment,
                Order = j.Order,
                ScheduleInListId = j.ScheduleInListId,
                SessionID = j.SessionID,
                SessionName = j.SessionName
            };
            return s;
        }

        public static JSession SessionToJSession(Session s)
        {
            JSession j = new JSession()
            {
                Comment = s.Comment,
                Order = s.Order,
                ScheduleInListId = s.ScheduleInListId,
                SessionID = s.SessionID,
                SessionName = s.SessionName
            };
            return j;
        }
        public static SubjectNotAt JSubNotAtToSubNotAt(JSubjectNotAt j)
        {
            SubjectNotAt s = new SubjectNotAt()
            {
                SubjectNotAtID = j.SubjectNotAtID,
                Comment = j.Comment,
                LessionID = j.LessionID,
                SessionID = j.SessionID,
                DayID = j.DayID,
                ScheduleInListId = j.ScheduleInListId,
                SubjectID = j.SubjectID
            };
            return s;
        }
        public static JSubjectNotAt SubNotAtToJSubNotAt(SubjectNotAt s)
        {
            JSubjectNotAt j = new JSubjectNotAt()
            {
                SubjectNotAtID = s.SubjectNotAtID,
                Comment = s.Comment,
                LessionID = s.LessionID,
                SessionID = s.SessionID,
                DayID = s.DayID,
                ScheduleInListId = s.ScheduleInListId,
                SubjectID = s.SubjectID
            };
            return j;
        }
        public static Subject JSubToSub(JSubject j)
        {
            Subject s = new Subject()
            {
                Comment = j.Comment,
                NotNeedTeacher = j.NotNeedTeacher,
                Primary = j.Primary,
                Require = j.Require,
                ScheduleInListId = j.ScheduleInListId,
                SubjectID = j.SubjectID,
                SubjectName = j.SubjectName,
            };
            return s;
        }
        public static JSubject SubToJSub(Subject s)
        {
            JSubject j = new JSubject()
            {
                Comment = s.Comment,
                NotNeedTeacher = int.Parse(s.NotNeedTeacher.ToString()),
                Primary = s.Primary,
                Require = s.Require,
                ScheduleInListId = s.ScheduleInListId,
                SubjectID = s.SubjectID,
                SubjectName = s.SubjectName,
                Type = s.Type
            };
            return j;
        }
        public static TeacherDetail JTeacherDToTeacherD(JTeacherDetail j)
        {
            TeacherDetail t = new TeacherDetail()
            {
                Comment = j.Comment,
                SubjectID = j.SubjectID,
                TeacherID = j.TeacherID
            };
            return t;
        }
        public static JTeacherDetail TeacherDToJTeacherD(TeacherDetail t)
        {
            JTeacherDetail j = new JTeacherDetail()
            {
                Comment = t.Comment,
                SubjectID = t.SubjectID,
                TeacherID = t.TeacherID
            };
            return j;
        }
        public static Teacher JTeacherToTeacher(JTeacher j)
        {
            Teacher t = new Teacher()
            {
                Comment = j.Comment,
                FullName = j.FullName,
                MinLession = j.MinLession,
                ScheduleInListId = j.ScheduleInListId,
                TeacherID = j.TeacherID
            };
            return t;
        }
        public static JTeacher TeacherTpJTeacher(Teacher t)
        {
            JTeacher j = new JTeacher()
            {
                Comment = t.Comment,
                FullName = t.FullName,
                MinLession = t.MinLession,
                ScheduleInListId = t.ScheduleInListId,
                TeacherID = t.TeacherID
            };
            return j;
        }
        public static JXSubject XSubToJXSub(XSubject xs)
        {
            JXSubject jx = new JXSubject()
            {
                IsPop = xs.isPop,
                Subject = AssignHelp.SubToJSub(xs.subject)
            };
            return jx;
        }

        public static JTeacherFixInfo TFIToJTFI(TeacherFixInfo tfi)
        {
            JTeacherFixInfo jtfi = new JTeacherFixInfo();
            jtfi.JTeach = TeacherTpJTeacher(tfi.teach);
            jtfi.LstDay = new List<JDay>();
            foreach (Day d in tfi.lstDay)
            {
                JDay jd = DayToJDay(d);
                jtfi.LstDay.Add(jd);
            }
            jtfi.LstLstSession = new List<List<JSession>>();
            foreach (List<Session> lstS in tfi.lstLstSession)
            {
                List<JSession> lstJS = new List<JSession>();
                foreach (Session s in lstS)
                {
                    JSession js = SessionToJSession(s);
                    lstJS.Add(js);
                }
                jtfi.LstLstSession.Add(lstJS);
            }
            return jtfi;
        }
        public static JProgramFull PFToJPF(ProgramFull pf)
        {
            JProgramFull jpf = new JProgramFull();
            jpf.Pro = ProgramToJProgram(pf.pro);
            jpf.LstSubject = new List<JSubject>();
            for (int i = 0; i < pf.lstSubject.Count; i++)
            {
                jpf.LstSubject.Add(SubToJSub(pf.lstSubject[i]));
            }
            jpf.LstNumLession = pf.lstNumLession;
            jpf.LstComment = pf.lstComment;
            return jpf;
        }
        public static JDGroup GroupToJDGroup(Group g)
        {
            JDGroup jdg = new JDGroup();
            jdg.GroupID = g.GroupID;
            jdg.GroupName = g.GroupName;
            jdg.ProgramID = g.ProgramID;
            Program p = DataBase.GetProgramById(g.ProgramID);
            jdg.ProgramName = p.ProgramName;
            Session s = DataBase.GetSessionById(g.SessionID);
            jdg.SessionID = g.SessionID;
            jdg.SessionName = s.SessionName;
            jdg.Comment = g.Comment;
            return jdg;
        }
    }

}
